﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MusicStore.Models;
using MusicStore.Storage;

namespace MusicStore.Controllers
{
    public class StoreController : Controller
    {
        private StoreDbContext db = new StoreDbContext(Settings.ConnectionString);
        //
        // GET: /Store/
        public ActionResult Index()
        {
            var genres = db.Genres.ToList();

            return View(genres);
        }
        //
        // GET: /Store/Browse?genre=Disco
        public ActionResult Browse(string genre)
        {
            var genreName = HttpUtility.HtmlEncode(genre);

            var genreModel = db.Genres.Include("Albums").FirstOrDefault(g => g.Name.Equals(genreName));

            return View(genreModel);
        }
        //
        // GET: /Store/Details/5
        public ActionResult Details(int id)
        {
            var album = new Album() { Title = "Album " + id };

            return View(album);
        }
    }
}
